package org.example.JVM.ByteCode.Handler;

import org.example.JVM.ByteCode.Type.ClassFile;
import org.example.JVM.ByteCode.Type.U2;

import java.nio.ByteBuffer;

/**
 * @description:
 * @author: farprt
 * @create: 2022-11-13 18:34
 **/
public class InterfacesHandler implements BaseByteCodeHandler {
    @Override
    public int order() {
        return 5;
    }

    @Override
    public void read(ByteBuffer codeBuf, ClassFile classFile) throws Exception {
        classFile.setInterfaces_count(new U2(codeBuf.get(), codeBuf.get()));
        int interfaces_count = classFile.getInterfaces_count().toInt();
        U2[] interfaces = new U2[interfaces_count];
        classFile.setInterfaces(interfaces);
        for (int i = 0; i < interfaces_count; i++) {
            interfaces[i] = new U2(codeBuf.get(), codeBuf.get());
        }
    }
}